package cn.tedu.exam1.exam.service.impl;

import cn.tedu.exam1.base.exception.ServiceException;
import cn.tedu.exam1.base.response.StatusCode;
import cn.tedu.exam1.exam.mapper.ExamMapper;
//import cn.tedu.ivos.user.pojo.dto.UserLoginParam;

import cn.tedu.exam1.exam.pojo.dto.CategoryQuery;
import cn.tedu.exam1.exam.pojo.dto.ExamQuery;
//import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.exam1.exam.pojo.entity.Exam;

import cn.tedu.exam1.exam.pojo.vo.CategoryVO;
import cn.tedu.exam1.exam.pojo.vo.ExamVO;
import cn.tedu.exam1.exam.service.ExamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class ExamServiceImpl implements ExamService {
    @Autowired
    ExamMapper examMapper;
   /*@Override
    public UserVO login(UserLoginParam userLoginParam) {
        log.debug("用户登录，参数：{}",userLoginParam);
        UserVO userVO = userMapper.selectByUsername(userLoginParam.getUsername());
        if(userVO==null){
            throw new ServiceException(StatusCode.USERNAME_ERROR);
        }
        if(!userVO.getPassword().equals(userLoginParam.getPassword())){
            throw new ServiceException(StatusCode.PASSWORD_ERROR);
        }
        return userVO;
    }

    @Override
    public void saveUser(UserSaveParam userSaveParam) {
        User user = new User();
        BeanUtils.copyProperties(userSaveParam,user);
        if(user.getId()==null){
            //新增用户时要判断该用户名是否存在
            if(userMapper.selectByUsername(user.getUsername())!=null){
                throw new ServiceException(StatusCode.USERNAME_ALREADY_EXISTS);
            }
            //注意:员工数据不是员工自己注册的，所以需要预设一个初始密码
            user.setPassword("123456");
            user.setCreateTime(new Date());
            userMapper.insert(user);
        }else{
            user.setUpdateTime(new Date());
            userMapper.update(user);
        }
    }
*/
    @Override
    public List<ExamVO> selectExam(ExamQuery examQuery) {
        List<ExamVO> list = examMapper.selectExam(examQuery);
        return list;
    }
    @Override
    public List<CategoryVO> selectCategory(CategoryQuery categoryQuery) {
        List<CategoryVO> list = examMapper.selectCategory(categoryQuery);
        return list;
    }


    /*@Override
    public void resetPassword(Long userId) {
        User user = new User();
        user.setId(userId);
        user.setPassword("admin");
        userMapper.update(user);
    }
@Override
    public List<CategoryVO> selectCategory(CategoryQuery categoryQuery) {
        List<CategoryVO> list = examMapper.selectCategory(categoryQuery);
        return list;
    }
    @Override
    public void updateStatus(Long userId, String status) {
        User user = new User();
        user.setId(userId);
        user.setStatus(status);
        userMapper.update(user);
    }

    @Override
    public void deleteUser(Long userId) {
        userMapper.deleteById(userId);
    }

    @Override
    public List<UserVO> selectAuditList(Long parentId) {
        ArrayList<UserVO> userVOList = new ArrayList<>();
        //根据上级用户id将审批人查出,添加到list中
        UserVO auditUser1 = userMapper.selectById(parentId);
        userVOList.add(auditUser1);
        //如果查到有上级,且上级还有上级
        if(auditUser1 != null && auditUser1.getParentId() !=null ){
            //查询上上级,添加到list中
            UserVO auditUser2 = userMapper.selectById(auditUser1.getParentId());
            userVOList.add(auditUser2);
        }
        return userVOList;
    }*/
}